<?php

namespace App\Repository\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

/**
 * Class Invoices.
 *
 * @package namespace App\Repository\Models;
 */
class Invoices extends Model implements Transformable
{
    use TransformableTrait;
    use SoftDeletes;

    protected $appends = ['invoice_type_name'];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id', 'order_code', 'invoice_message', 'invoice_type', 'invoice_title', 'tax_code', 'invoice_address', 'invoice_tel',
        'invoice_bank', 'invoice_account', 'shipping_id', 'shipping_name', 'shipping_cost', 'courier_number', 'post_address', 'post_contacts',
        'post_tel', 'invoice_status', 'invoice_code', 'invoice_number', 'invoice_price', 'open_invoice_at', 'open_invoice_user', 'create_user',
        'update_user', 'remark',];

    public static $invoice_type_map = [
        1 => '普通发票',
        2 => '专用发票'
    ];

    public function getInvoiceTypeNameAttribute()
    {
        if(isset($this->attributes['invoice_type'])){
            return array_get(self::$invoice_type_map, $this->attributes['invoice_type']);
        }
        return '';
    }
}
